<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/base/jsp/include.jsp"%>
<style>
</style>
<script type="text/javascript">
    var id = "${id}";
    var parent = "${parent}";
    var level = "${level}";
    var groupId= '${groupId}';
    var tree;
    var submitForm = function($dialog, $grid, $pjq) {
        if ($('form').form('validate')) {
            var obj=sy.serializeObject($('form'));
            /* var t = $("#userId").combotree('tree');
            var n =t.tree('getSelected'); */
            var usersId = $("#userId").combotree("getValues");
            if(usersId){
            	usersId = usersId.join(',');
            }
            var url=sy.contextPath + '/user/findDeptUser';
            $.post(url, {usersId:usersId,actId:id}, function(result) {
                if (result.code == 0) {
                    $grid.datagrid('reload');
                    $dialog.dialog('destroy');
                } else {
                    $pjq.messager.e('添加失败,'+result.msg);
                }
            }, 'json'); 
        }
    };

    $(function() {    	
        $('#userId').combotree({        	
            url:sy.contextPath + '/dept/findDeptList.do',
            idField : 'id',
            /* treeField : 'deptName', */
            textField : 'text',
            parentField : 'parent', 
            multiple: true,
            checkbox: true,
            onLoadSuccess: function (node, data) {
            	$('#userId').combotree('tree').tree("collapseAll");
            	if(id != ''){
            		checkExistUser(id);
            	}
            	
            },           
        });
        
    });
    
    function checkExistUser(id){
        var url = sy.contextPath + '/user/checkExistMeetingUser.do';
        $.post(url, {meetingId : id},  function(result) {
            if (result) {
                $('form').form('load', result);
                $("#userId").combotree("setValues",result);
            }
            parent.$.messager.progress('close');
        }, 'json');
    }
</script>
</head>
<body>
    <form id="form" method="post">
        <input name="id" type="hidden" />
        <input name='groupId' type="hidden"/>
        <div style="padding:15px;font-size: 12px">
            <table style="table-layout:fixed;" border="0" cellspacing="0" class="formtable">
                <tr>
                    <th style="width:100px;">请选择人员：</th>
                    <td>
                        <select class="easyui-combotree" name="userId" id="userId" style="width:156px;"/>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>